package com.tubruk.util.dialog;

import java.util.Calendar;

import com.tubruk.todo.activity.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;

public class DateTimePicker extends Dialog {
	
		public interface DateTimePickerListener {
			public void okClicked(Calendar calendar);
			public void cancelClicked();
		}
		
		private DateTimePickerListener dateTimePickerListener;
		
	 	public DateTimePicker(Context context, DateTimePickerListener dateTimePickerListener) {
	        super(context, R.style.DatePickerTheme);
	        this.dateTimePickerListener = dateTimePickerListener;
	    }

	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.datetime_dialog);
	        setTitle("Date Time Picker");
	        
	        
	        Button okBtn = (Button) findViewById(R.id.DateTimeOKBtn);
	        okBtn.setOnClickListener(new OKListener());
	        
	        Button cancelBtn = (Button) findViewById(R.id.DateTimeCancelBtn);
	        cancelBtn.setOnClickListener(new CancelListener());
	        
	    }

	    private class OKListener implements android.view.View.OnClickListener {
	        public void onClick(View v) {
	            //readyListener.ready(String.valueOf(etName.getText()));
	        	DatePicker dt = (DatePicker) findViewById(R.id.DatePicker);
	        	int year = dt.getYear();
	        	int month = dt.getMonth();
	        	int day = dt.getDayOfMonth();
	        	
	        	TimePicker tm = (TimePicker) findViewById(R.id.TimePicker);
	        	int hourOfDay = tm.getCurrentHour();
	        	int minute = tm.getCurrentMinute();
	        	
	        	Calendar calendar = Calendar.getInstance();
	        	calendar.set(year, month, day, hourOfDay, minute);
	        	dateTimePickerListener.okClicked(calendar);
	        	
	            DateTimePicker.this.dismiss();
	        }
	    }
	    
	    private class CancelListener implements android.view.View.OnClickListener {
	        public void onClick(View v) {
	            //readyListener.ready(String.valueOf(etName.getText()));
	        	dateTimePickerListener.cancelClicked();
	            DateTimePicker.this.dismiss();
	        }
	    }
}
